package linear.tree;

/**
 * @Author: fzykd
 * Date: 2024-04-12
 * Time: 20:30
 * User: LQH
 */

//节点类型
class Node {
    public char val;
    //左节点
    public Node left;
    //右节点
    public Node right;

    public Node(char val) {
        this.val = val;
    }
}

//二叉树 链式存储实现二叉树
public class BinaryTree {

    //创建二叉树
    public Node create() {
        //创建节点
        Node a = new Node('A');
        Node b = new Node('B');
        Node c = new Node('C');
        Node d = new Node('D');
        Node e = new Node('E');
        Node f = new Node('F');
        Node g = new Node('G');
        Node h = new Node('H');

        //手动节点指向 形成二叉树
        a.left = b;
        a.right = c;
        b.left = d;
        b.right = e;
        e.right = h;
        c.left = f;
        c.right = g;

        //创建之后返回根节点
        return a;
    }

    //前中后序遍历
    //前序
    public void preOrder(Node root) {
        if (root == null) {
            return;
        }
        System.out.print(root.val + " ");
        preOrder(root.left);
        preOrder(root.right);
    }

    //中序遍历  左根右
    public void inOrder(Node root) {
        if (root == null) {
            return;
        }
        inOrder(root.left);
        System.out.print(root.val + " ");
        inOrder(root.right);
    }

    //后序遍历 左右根
    public void postOrder(Node root) {
        if (root == null) {
            return;
        }
        postOrder(root.left);
        postOrder(root.right);
        System.out.print(root.val + " ");

    }

    //二叉树节点个数

    //二叉树叶子节点个数

    //获取第k层节点数

    //获取二叉树的高度

    //二叉树的查询

}
